import { app, BrowserWindow, nativeImage, ipcMain } from 'electron'
import icon from '../renderer/src/assets/images/logo.png'
import { join } from 'path'
import { is } from '@electron-toolkit/utils'

export const width = 1000
export const height = 800

export function createWindow(): BrowserWindow {

  const loginWindow = new BrowserWindow({
    width: width,
    height: height,
    show: false,
    frame: false, //  以去除操作栏（包括标题栏）
    resizable: false, //  禁止窗口大小拖动
    autoHideMenuBar: true,
    icon: nativeImage.createFromDataURL(icon),
    webPreferences: {
      preload: join(__dirname, '../preload/index.js'),
      sandbox: false
    }
  })

  if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
    loginWindow.loadURL(process.env['ELECTRON_RENDERER_URL'] + '/#/login')
  } else {
    loginWindow.loadFile(join(__dirname, '../renderer/index.html'), { hash: '/login' })
  }
  // 监听子窗口关闭事件
  loginWindow.on('closed', () => {})
  loginWindow.on('ready-to-show', () => {
    loginWindow.show()
  })


  // 开发时打开 DevTools
  if (process.env.VITE_APP_ENV === 'development') {
    loginWindow.webContents.openDevTools()
  }

  return loginWindow
}
